package com.zut.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.zut.pojo.Parents;
import com.zut.service.ParentsService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Resource
    private ParentsService parentsService;


    /**
     * 登录功能
     */

    @PostMapping("/login")
    public String login(HttpSession session,String name,String password,Model model){

        QueryWrapper<Parents> wrapper=new QueryWrapper<>();
        wrapper.eq("parname",name).eq("parpwd",password);
        Parents parents=parentsService.getOne(wrapper);
        if (parents!=null){
            session.setAttribute("loginParent",parents);
            return "redirect:/userpage";
        }else {

            model.addAttribute("msg","账号或密码错误，请重新输入");
            return "log-in";
        }

    }

}
